<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="_csrf" th:content="${_csrf.token}"/>
    <meta name="_csrf_header" th:content="${_csrf.headerName}"/>
    <title>修改密码</title>
    <script th:src="@{/static/ckeditor/ckeditor.js}"></script>
</head>
<body>

<div th:replace="header :: nav"></div>

<script>
    function change() {
        var token = $("meta[name='_csrf']").attr("content");
        var header = $("meta[name='_csrf_header']").attr("content");
        var oldPassword = $("#oldPassword").val();
        var newPassword = $("#newPassword").val();
        var data = {
            "oldPassword":oldPassword,
            "newPassword":newPassword
        }
        $.ajax({
            url: "/changePassword",
            type:"POST",
            dataType:"json",
            beforeSend: function(request) {
                request.setRequestHeader(header, token);
            },
            timeout:5000,
            data: data,
            success: function (result) {
                if(result==true)
                    window.location.href="/me.html";
                else
                    alert("旧密码错误！")
            },
            error:function (err) {
                alert("网络错误！"+err.toString());
            }
        });
    }

</script>
<div class="container">

    <div th:replace="header :: meLeft"></div>

    <div class="col-xs-10">
        <div class="form-horizontal">
            <div class="form-group">
                <label for="oldPassword" class="col-sm-2 control-label">OldPassword:</label>
                <div class="col-xs-10">
                    <input type="password" class="form-control" id="oldPassword" placeholder="OldPassword">
                </div>
            </div>

            <div class="form-group">
                <label for="newPassword" class="col-sm-2 control-label">NewPassword:</label>
                <div class="col-xs-10">
                    <input type="password" class="form-control" id="newPassword" placeholder="NewPassword">
                </div>
            </div>
            <div class="form-group">
                <label for="confirmPassword" class="col-sm-2 control-label">ConfirmPassword:</label>
                <div class="col-xs-10">
                    <input type="password" class="form-control" id="confirmPassword" placeholder="ConfirmPassword">
                </div>
            </div>

            <div class="form-group">
                <button class="btn btn-default" onclick="change()">保存</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>